package com.tmpt.controller.action;


import com.opensymphony.xwork2.ActionSupport;
import com.tmpt.dto.A1OperationlogDto;
import com.tmpt.dto.A2PostDto;
import com.tmpt.dto.A2UserDto;
import com.tmpt.dto.Result;
import com.tmpt.freemarker.utils.FreemarkerUtils;
import com.tmpt.service.IOperationlogService;
import com.tmpt.service.IOrgService;
import com.tmpt.utils.WebUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Scope("prototype")
public class OlapAction extends ActionSupport{
	private Logger log = Logger.getLogger(this.getClass());
	
	private static final long serialVersionUID = 1L;

	private String pageTitle;
	private String pageName;
	private String schemaFilename;
	private String mdx;

	private String result;
	private A1OperationlogDto oprDtoBack = new A1OperationlogDto(WebUtils.getRequest(), A1OperationlogDto.UserTypeBack);
	 
	public String genQueryPageAction(){
		try{
			System.out.println(pageTitle);
			System.out.println(pageName);
			System.out.println(schemaFilename);
			System.out.println(mdx);

			Map<String,Object> map = new HashMap<String,Object>();
			map.put("pageTitle",pageTitle);
			map.put("schemaFilename",schemaFilename);
			map.put("mdx",mdx);
			map.put("pageName",pageName);
			genOlapQueryPage(map);
		}catch (Exception e) {
			e.printStackTrace();
			this.result = e.getLocalizedMessage();
		}
		return "input";
	}


	private void genOlapQueryPage(Map map){
		String pageName = map.get("pageName").toString();
		if(pageName.lastIndexOf(".jsp")<0){
			pageName+=".jsp";
		}
		String webPath = ServletActionContext.getServletContext().getRealPath("/");
		String pathFtl = webPath+"\\freemarker\\olap\\";
		String pathOut ="/files1/bi/mondrian/";
		FreemarkerUtils fmUtils = new FreemarkerUtils(pathFtl,pathOut);
		fmUtils.fprint("query.jsp.ftl", map, pageName);
	}


	public String getPageName() {
		return pageName;
	}

	public void setPageName(String pageName) {
		this.pageName = pageName;
	}

	public Logger getLog() {
		return log;
	}

	public void setLog(Logger log) {
		this.log = log;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public String getPageTitle() {
		return pageTitle;
	}

	public void setPageTitle(String pageTitle) {
		this.pageTitle = pageTitle;
	}

	public String getSchemaFilename() {
		return schemaFilename;
	}

	public void setSchemaFilename(String schemaFilename) {
		this.schemaFilename = schemaFilename;
	}

	public String getMdx() {
		return mdx;
	}

	public void setMdx(String mdx) {
		this.mdx = mdx;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public A1OperationlogDto getOprDtoBack() {
		return oprDtoBack;
	}

	public void setOprDtoBack(A1OperationlogDto oprDtoBack) {
		this.oprDtoBack = oprDtoBack;
	}
}
